-- 获取可重入锁
local lockKey = KEYS[1]
local threadField = ARGV[1]
local releaseTime = ARGV[2]
-- 锁不存在
if (redis.call('exists', lockKey) == 0) then
    redis.call('hset', lockKey, threadField, '1')
    redis.call('expire', lockKey, releaseTime)
    return 1
end
-- 锁存在，判断是不是自己的锁
if (redis.call('hexists', lockKey, threadField) == 1) then
    redis.call('hincrby', lockKey, threadField, '1')
    redis.call('expire', lockKey, releaseTime)
    return 1
end
-- 锁存在，切不是自己的锁
return 0
